<?php
class stubbed_Bootstrap{

	public function __construct(){
		spl_autoload_register(array($this, 'autoloadClass'));
		spl_autoload_register(array($this, 'autoloadModel'));
	}

	public function __destruct(){
		spl_autoload_unregister(array($this, 'autoloadClass'));
		spl_autoload_unregister(array($this, 'autoloadModel'));
	}

	/**
	* Autoloads application classes
	*
	* @param string $class
	* @return boolean
	*/
	public function autoloadClass($class) {
		static $classPath;
		
		if(!$classPath){
			$classPath = rtrim( APP . 'classes' . DIRECTORY_SEPARATOR, '\\/') . DIRECTORY_SEPARATOR;
		}
		
		$file = $classPath . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
		if(file_exists($file)) {
			require_once $file;
			return true;
		}
		return false;
	}

	/**
	* Autoloads application model classes
	*
	* @param string $class
	* @return boolean
	*/
	public function autoloadModel($class) {
		// Get paths (once)
		static $modelPath;

		if(!$modelPath){
			$modelPath = rtrim( APP . 'models' . DIRECTORY_SEPARATOR, '\\/') . DIRECTORY_SEPARATOR;
		}
		
		$file = $modelPath . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
		if(file_exists($file)) {
			require_once $file;
			return true;
		}
		return false;
	}
}